<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>xinldb test</title>
    <script src="../../../xin-js/utils/jquery.js" type="text/javascript"></script>
    <script src="../../../xin-js/xinstore/xinstore.js" type="text/javascript"></script>
</head>
<body>
<div id="debuginfo"></div>


<script>

/*
debuginfo( "Browser support:<br />" );
var localstorage = window.localStorage ? true : false;
debuginfo( "localStorage: "+localstorage+"<br />" );
var flash = true;
if( !deconcept ){
    flash = false;
    debuginfo( "!deconcept<br />" );
}
if( !deconcept.SWFObjectUtil ){
    flash = false;
    debuginfo( "!deconcept.SWFObjectUtil<br />" );
}
var flashVersion = deconcept.SWFObjectUtil.getPlayerVersion().major;
if( flashVersion < 8 ){
    flash = false;
    debuginfo( "!flash version: "+flashVersion+"<br />" );
}
debuginfo( "flash: "+flash+"<br />" );
var gears = (window.google && window.google.gears) ? true : false;
debuginfo( "gears: "+gears+"<br />" );
var database = window.openDatabase ? true: false;
debuginfo( "database: "+database+"<br />" );

var gs = window.globalstorage ? true: false;
debuginfo( "gs: "+gs+"<br />" );

var ie = window.ActiveXObject ? true : false;
debuginfo( "ie: "+ie+"<br />" );

*/

xinstore.init( null, { swf: "../../../xin-js/xinstore/XINStore.swf" } );
xinstore.ready( test_1 );

setTimeout( function(){
    xinstore.init( "ie", { swf: "../../../xin-js/xinstore/XINStore.swf" } );
    xinstore.ready( test_1 );
}, 5000 );

function debuginfo( msg ){
    var html = $("#debuginfo").html();
    html += msg;
    $("#debuginfo").html( html );
};
function test_1(){
    debuginfo( "<br />test on "+xinstore.store.type+"<br /><br />" );
    var f1 = function(){
        debuginfo( "test f1, 7 cases!<br />" );
        var db = xinstore.createDatabase( "test_xinldb_f1" );
        if( !isInArray( xinstore.databases(), "test_xinldb_f1" ) ){
            debuginfo( "error, f1, 0...<br />" );
        }else{
            debuginfo( "f1.0 ok.<br />" );
        }
        var tb = db.createTable( "user" );
        if( !isInArray( db.tables(), "user" ) ){
            debuginfo( "error, f1, 1...<br />" );
        }else{
            debuginfo( "f1.1 ok.<br />" );
        }
        tb.update( 1, { "name": "hxh", "age": 27, "title": "programmer", "skill": "python,c,c++,javascript,php,mysql" } );
        tb.update( 2, { "name": "wac", "age": 25, "title": "programmer", "skill": "php,mysql" } );
        tb.update( 3, { "name": "yht", "age": 26, "title": "programmer", "skill": "javascript,php,mysql" } );
        if( tb.get(1)["age"] != 27 ){
            debuginfo( "error, f1, 2...<br />" );
        }else{
            debuginfo( "f1.2 ok.<br />" );
        }
        if( tb.all()[1][1]["name"] != "wac" ){
            debuginfo( "error, f1, 3...<br />" );
        }else{
            debuginfo( "f1.3 ok.<br />" );
        }
        tb.remove( 2 );
        if( tb.all().length != 2 ){
            debuginfo( "error, f1, 4...<br />" );
        }else{
            debuginfo( "f1.4 ok.<br />" );
        }
        tb.remove( 3 );
        if( tb.recordIDs() != 1 ){
            debuginfo( "error, f1, 5...<br />" );
        }else{
            debuginfo( "f1.5 ok.<br />" );
        }
        db.dropTable( "user" );
        if( isInArray( db.tables(), "user" ) ){
            debuginfo( "error, f1, 6...<br />" );
        }else{
            debuginfo( "f1.6 ok.<br />" );
        }
        xinstore.dropDatabase( "test_xinldb_f1" );
        if( isInArray( xinstore.databases(), "test_xinldb_f1" ) ){
            debuginfo( "error, f1, 7...<br />" );
        }else{
            debuginfo( "f1.7 ok.<br />" );
        }
        
        debuginfo( "test f1 passed !" );
    };
    
    f1();
};
</script>
</body>
</html>
